﻿
using System;
using System.Collections.Generic;
using DocumentBuilder.Components;

namespace DocumentBuilder
{
    public class DocumentLoadContext : IJsonConvertible
    {
        public Dictionary<string, string> Attributes { get; set; }
        public string ContainerId { get; set; }

        public DocumentLoadContext()
        {
            Attributes = new Dictionary<string, string>();
        }

        #region IJsonConvertible Members

        public void PaintJsonString(System.Text.StringBuilder jsonCanvas)
        {
            int cnt = 0;
            foreach (var key in Attributes.Keys)
            {
                if (cnt == 0)
                    jsonCanvas.Append("\"args\" : [");

                jsonCanvas.Append(string.Format("\"{0}\": \"{1}\"", key, Attributes[key]));

                if (cnt == Attributes.Count - 1)
                    jsonCanvas.Append("]");

                cnt++;
            }

            if (!String.IsNullOrEmpty(ContainerId))
            {
                if (cnt > 0)
                    jsonCanvas.Append(",");

                jsonCanvas.Append("\"containerElement\": \"" + ContainerId + "\"");
            }
        }

        #endregion
    }
}
